import React, { Component } from "react";
// todo 整个项目需要用BrowserRouter套住,只有在这个组件的内部才能使用路由
// todo Link相当于改变url的a标签，对应vue里面router-link
// todo 一个Route表示一个路由
// todo Switch是将包容性转成排他性路由
import { Link, Route, Switch } from "react-router-dom";

class Home extends Component {
  render() {
    return <div>这是首页页面</div>;
  }
}

class About extends Component {
  render() {
    return <div>这是关于页面</div>;
  }
}

class Mine extends Component {
  render() {
    return <div>这是我的页面</div>;
  }
}

class App extends Component {
  render() {
    return (
      <>
        <h2>react-router-basic</h2>
        <ul>
          <li>
            <Link to="/">home</Link>
          </li>
          <li>
            <Link to="/about">about</Link>
          </li>
          <li>
            <Link to="/mine">mine</Link>
          </li>
        </ul>

        <hr />

        {/* react路由默认是包容性路由 */}
        {/* exact表示精确匹配,默认是模糊匹配 */}
        <Switch>
          <Route path="/" component={Home} exact></Route>
          <Route path="/about" component={About}></Route>
          <Route path="/mine" component={Mine}></Route>
        </Switch>
      </>
    );
  }
}

export default App;
